package com.myzl.web.controller.coal;

import com.myzl.coal.domain.Rfid;
import com.myzl.coal.service.IRfidService;
import com.myzl.common.annotation.Log;
import com.myzl.common.core.controller.BaseController;
import com.myzl.common.core.domain.AjaxResult;
import com.myzl.common.core.page.TableDataInfo;
import com.myzl.common.enums.BusinessType;
import com.myzl.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * rfid记录Controller
 *
 * @author myzl
 * @date 2023-06-13
 */
@RestController
@RequestMapping("/coal/rfid")
public class RfidController extends BaseController
{
    @Autowired
    private IRfidService rfidService;

    /**
     * 查询rfid记录列表
     */
    @PreAuthorize("@ss.hasPermi('coal:rfid:list')")
    @GetMapping("/list")
    public TableDataInfo list(Rfid rfid)
    {
        startPage();
        List<Rfid> list = rfidService.selectRfidList(rfid);
        return getDataTable(list);
    }

    /**
     * 导出rfid记录列表
     */
    @PreAuthorize("@ss.hasPermi('coal:rfid:export')")
    @Log(title = "rfid记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Rfid rfid)
    {
        List<Rfid> list = rfidService.selectRfidList(rfid);
        ExcelUtil<Rfid> util = new ExcelUtil<Rfid>(Rfid.class);
        util.exportExcel(response, list, "rfid记录数据");
    }

    /**
     * 获取rfid记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('coal:rfid:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rfidService.selectRfidById(id));
    }

    /**
     * 新增rfid记录
     */
    @PreAuthorize("@ss.hasPermi('coal:rfid:add')")
    @Log(title = "rfid记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Rfid rfid)
    {
        return toAjax(rfidService.insertRfid(rfid));
    }

    /**
     * 修改rfid记录
     */
    @PreAuthorize("@ss.hasPermi('coal:rfid:edit')")
    @Log(title = "rfid记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Rfid rfid)
    {
        return toAjax(rfidService.updateRfid(rfid));
    }

    /**
     * 删除rfid记录
     */
    @PreAuthorize("@ss.hasPermi('coal:rfid:remove')")
    @Log(title = "rfid记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rfidService.deleteRfidByIds(ids));
    }
}
